﻿using AutoMapper;
using MediatR;
using MyMES.Domain.W.Liststructure;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.W.realize;
using NLog.Web.LayoutRenderers;

namespace MyMES.Writer.API.Application.CommendHandlers.W.realize
{
    public class DelBillingmanagementCommandHanders : IRequestHandler<DelBillingmanagementCommands, APIResult<Billingmanagement>>
    {
        private readonly IBaseRepository<Billingmanagement> baseRepository;
        private readonly IMapper mapper;

        public DelBillingmanagementCommandHanders(IBaseRepository<Billingmanagement> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 删除开票到票信息
        /// </summary>
        /// <param name="request">删除开票到票信息</param>
        /// <param name="cancellationToken">2025年4月14日11:18:14</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Billingmanagement>> Handle(DelBillingmanagementCommands request, CancellationToken cancellationToken)
        {
            APIResult<Billingmanagement> result=new APIResult<Billingmanagement> ();
            result.Code = APIEnum.删除成功;
            result.Msg = "删除成功";
            var map=mapper.Map<Billingmanagement>(request);
            var sql = $"Update Billingmanagement set IsDelete=true where Bid='{request.Bid}'";
            await baseRepository.Update(map, sql);
            return result;
        }
    }
}
